#!/usr/bin/env Python
# -*- coding:utf-8 -*-
# chatbot.py
# A chat robot demo
# author: De8uG


class RobotUI:
    def __init__(self, name, admin):
        self.name = name
        self.admin = admin

    def talk(self):
        self.welcome()
        words = input('你：')
        answer = admin.answer(words)
        print(f'{self.name}: {answer}')
    
    def welcome(self):
        print(f'hello，我是机器人{self.name}')


class RobotAdmin:
    def __init__(self):
        self.data = self.load_data()  # {}

    def load_data(self):
        with open('db.pkl', 'rb') as f:
            data = pickle.loads(f.read())
            print(data)
            return data
            
    def answer(self, listen):
        # answer something from listen
        if listen in self.data:
            return self.data[listen]
        

def main():
    """
    请扩展如下功能，欢迎写好了到群里炫富！

    多轮交互，还记得while循环吧，记得给个退出提示，刹车很重要！
    根据关键词进行回答，前面学的字符串查找和正则不是吃素的哦！
    扩展admin功能，可以不生成对象情况下自定义添加数据（staticmethod用过没？）
    你还想干啥？Just Do IT！
    """
    admin = RobotAdmin()
    robot = RobotUI('小8', admin)
    robot.talk()

if __name__ == '__main__':
    main()
